package com.minaClient.service;

import org.apache.log4j.Logger;
import org.apache.mina.core.session.IoSession;

/**
 * Description:
 */
public class SessionManager {

    private static SessionManager mInstance=null;

    private IoSession mSession;
    Logger log=Logger.getLogger(SessionManager.class.getName());
    public static SessionManager getInstance(){
        if(mInstance==null){
            synchronized (SessionManager.class){
                if(mInstance==null){
                    mInstance = new SessionManager();
                }
            }
        }
        return mInstance;
    }

    private SessionManager(){}

    public void setSeesion(IoSession session){
        this.mSession = session;
    }

    public void writeToServer(Object msg){
        if(mSession!=null){
        	log.debug( "客户端准备发送消息"+msg);
            mSession.write(msg);
        }
    }

    public void closeSession(){
        if(mSession!=null){
        	log.debug("关闭session");
            mSession.closeOnFlush();
        }
    }

    public void removeSession(){
    	log.debug("清空session");
        this.mSession=null;
    }
}
